Skip to content

feat(NIC-stats): added NIC statistics in shared memory with FFI and RPC, new states for yaml#713

Open
kt0ns wants to merge 10 commits intomainfrom
feature/nic-counters
Open

feat(NIC-stats): added NIC statistics in shared memory with FFI and RPC, new states for yaml#713
kt0ns wants to merge 10 commits intomainfrom
feature/nic-counters

Conversation

@kt0ns
Copy link
Copy Markdown
Collaborator

@kt0ns kt0ns commented May 4, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 4, 2026 10:05
@kt0ns kt0ns requested review from a team as code owners May 4, 2026 10:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a “global” dataplane shared-memory region to publish NIC statistics as counters, wires those counters through the C agent API and Go FFI, and exposes them via a new gRPC RPC. It also extends the dataplane YAML config schema to include globalstats storage sizing and NIC stats update cadence.

Changes:

  • Introduce a global (non-instance) dp/cp shared-memory config region and a background NIC stats thread that updates counters in shared memory.
  • Unify worker counter registry/storage naming (worker_counterscounters) and add a new yanet_get_nic_counters API + Go FFI wrapper.
  • Add CountersService.NIC gRPC endpoint and new YAML config sections (globalstats, updatetimes).

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
mock/mock.c Update mock initialization to link the renamed counter registry field.
lib/dataplane/config/zone.h Rename per-instance counter fields to counters / counter_storage.
lib/controlplane/agent/agent.c Add shared-memory accessor for global dp_config and a NIC counters getter.
dataplane/worker.c Switch worker counter registration/storage usage to the renamed fields.
dataplane/meson.build Include new globalstat.c in dataplane build.
dataplane/main.c Start dataplane “daemons” (NIC stats thread) from main.
dataplane/globalstat.h Define NIC/global stats structs and daemon entrypoints.
dataplane/globalstat.c Implement NIC stats polling and counter updates.
dataplane/dataplane.h Add global dp/cp config pointers and global stats storage in dataplane struct; declare daemon starter.
dataplane/dataplane.c Allocate global shared-memory region; init global counters/storage; create NIC stats thread.
dataplane/config.h Add globalstat memory sizing and updatetimes config structs.
dataplane/config.c Extend YAML state machine to parse globalstats/updatetimes.
controlplane/ynpb/counters.proto Add NIC RPC and NICCounterRequest message.
controlplane/internal/gateway/counters_service.go Implement NIC RPC handler using global shared-memory dp_config.
controlplane/ffi/shm.go Add DPGlobalConfig() accessor and NICCounters() wrapper around new C API.
api/counter.h Export yanet_get_nic_counters in the public C API.
api/agent.h Export yanet_shm_global_dp_config in the public C API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +73 to +76
struct dp_config *
yanet_shm_global_dp_config(struct yanet_shm *shm) {
return dp_config_nextk((struct dp_config *)shm, yanet_shm_instance_count(shm));
}
Comment thread dataplane/dataplane.c
Comment on lines +360 to +371
uint64_t dp_memory = config->globalstat.dp_memory;
uint64_t cp_memory = config->globalstat.cp_memory;

struct dp_config *dp_config = (struct dp_config *)storage;
dataplane->global_dp_config = dp_config;

block_allocator_init(&dp_config->block_allocator);
block_allocator_put_arena(
&dp_config->block_allocator,
storage + sizeof(struct dp_config),
dp_memory - sizeof(struct dp_config)
);
Comment thread dataplane/config.c
Comment on lines +516 to +520
// TODO: delete
dataplane->globalstat.cp_memory = (1 << 30) / 2;
dataplane->globalstat.dp_memory = (1 << 30) / 2;
dataplane->updatetimes.nic_updatetime = 1;

Comment thread dataplane/config.c
Comment on lines 493 to 501
break;
case state_connection:
state = state_connections;
break;
case state_globalstat:
state = state_dataplane;
break;
default:
goto error;
Comment thread dataplane/dataplane.c
Comment on lines +787 to 807
int
dataplane_daemons_start(struct dataplane *dataplane, struct dataplane_config *config) {
pthread_t thread_id;
pthread_create(&thread_id, NULL, stat_thread, dataplane);

struct stat_thread_args {
struct dataplane *dataplane;
struct dataplane_config *config;
};

struct stat_thread_args *args = malloc(sizeof(struct stat_thread_args));
if (args == NULL) {
LOG(ERROR, "failed to allocate memory for stat_thread_args");
return -1;
}

args->dataplane = dataplane;
args->config = config;

pthread_create(&thread_id, NULL, stat_nic_thread, args);

return 0;

message DeviceCountersRequest { string device = 1; }

message NICCounterRequest { string device = 1; }
Comment on lines +132 to +138
func (m *CountersService) NIC(
ctx context.Context,
request *ynpb.NICCounterRequest,
) (*ynpb.CountersResponse, error) {
dpConfig := m.shm.DPGlobalConfig()
counterValues := dpConfig.NICCounters()

Comment thread dataplane/main.c
Comment on lines 90 to 98
LOG(INFO, "start dataplane");
dataplane_start(&dataplane);

LOG(INFO, "start dataplane daemons");
dataplane_daemons_start(&dataplane, config);

// FIXME: infinite sleep effectively
LOG(INFO, "wait dataplane");
dataplane_stop(&dataplane);
Comment thread dataplane/globalstat.c
Comment on lines +20 to +38
static int
counter_register_counter(
struct dp_config *dp_config, const char *name, uint64_t size
) {
yanet_error *err = NULL;
uint64_t rc = counter_registry_register(
&dp_config->counters, name, size, &err
);
if (rc == COUNTER_INVALID) {
LOG(ERROR,
"failed to register '%s' counter: %s",
name,
yanet_error_message(err));
yanet_error_free(err);
return -1;
}

return rc;
}
Comment thread dataplane/dataplane.c
Comment on lines +791 to +805
struct stat_thread_args {
struct dataplane *dataplane;
struct dataplane_config *config;
};

struct stat_thread_args *args = malloc(sizeof(struct stat_thread_args));
if (args == NULL) {
LOG(ERROR, "failed to allocate memory for stat_thread_args");
return -1;
}

args->dataplane = dataplane;
args->config = config;

pthread_create(&thread_id, NULL, stat_nic_thread, args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants